<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<?php
if(!isset($_SESSION)){
	session_start();
}

if(!isset($_SESSION["adminName"]) || (empty($_SESSION["adminName"]))){
	header ("Location: ../index.php");
}
?>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Edit Page</title>
    <link href="../../Styles/adminstype.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../js/admin_script.js"></script>
</head>
<body>
<?php
	$getMaDH = "";
	$getKhachHang = "";
	$getDiaChi ="";
	$getTongTien = "";
	$getNgayDH = "";
	$getTinhTrang = "";
	$id = $_SESSION["edit"];
	$comboBox = "";
	
	if(empty($_REQUEST["btnSua"])){
		if($id != "") // kiem tra du lieu
		{
			$sql = "SELECT dondathang . * , taikhoan . * , tinhtrang . * 
					FROM dondathang, taikhoan, tinhtrang
					WHERE dondathang.MaTaiKhoan = taikhoan.MaTaiKhoan
					AND dondathang.MaTinhTrang = tinhtrang.MaTinhTrang AND dondathang.MaDonDatHang = $id";
				
			require_once "../database/DataProvider.php";
			$result =  DataProvider::ExecuteQuery($sql);
				
			if(!empty($result))
			{
				while ($row=mysql_fetch_array($result)){
					$getMaDH = $row["MaDonDatHang"];
					$getKhachHang = $row["TenHienThi"];
					$getDiaChi = $row["DiaChi"];
					$getTongTien = $row["TongThanhTien"];
					$getNgayDH = $row["NgayLap"];
					$getTinhTrang = $row["MaTinhTrang"];
				}	
			}
		}
		
		
		// tạo combo tinh trang
		$width = 160;;
		$name ="TTDDH";
		$active_sltTenTH = $getTinhTrang;
		$tatca = "Tất Cả";
		$comboBox = '<select style="width:'.$width.'px" name="'.$name.'" id="'.$name.'" >'."\n";
		
		$sql = "select * from tinhtrang";
		require_once "../database/DataProvider.php";
		$result =  DataProvider::ExecuteQuery($sql);
		
		if(!empty($result)){
			while($row = mysql_fetch_array($result))
			{
				$comboBox .= '<option value="'.$row["MaTinhTrang"].'"';
				if($active_sltTenTH == $row["MaTinhTrang"]) $comboBox .= ' selected="selected" ';
				$comboBox .= '>'.$row["TenTinhTrang"]."</option>\n";
			}
		}
		$comboBox .= "</select>\n";
		
	}
?>
<table>
	<tr class="boxContentTitle">
		<td>Cập nhật trạng thái đơn đặt hàng</td>
	</tr>
	<tr>
		<td>
			 <form action="resource/form_edit_order.php" method="post" name="form_edit_order">
				<table class="tableBoxView">
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Mã đơn hàng: </td>
						<td><?php echo($getMaDH);?></td>
					</tr>
									<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tên khách hàng: </td>
						<td><?php echo($getKhachHang);?></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Địa chỉ</td>
						<td><?php echo($getDiaChi);?></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tổng tiền: </td>
						<td><?php echo($getTongTien);?></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Ngày đặt hàng: </td>
						<td><?php echo($getNgayDH);?></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Loại tài khoảng</td>
						<td><?php echo($comboBox);?></td>
					</tr>
					<tr>
						<td><td>
						<td></td>
						<td><input type="submit" name="btnSua" value="Save"/></td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
			<?php
			if(!empty($_REQUEST["btnSua"]))//có yeu cau sua
			{
				$tenTT = $_REQUEST["TTDDH"];

				if($tenTT != "") //  kiểm tra 
				{
					$sql = "UPDATE dondathang 
    						SET MaTinhTrang=" .$tenTT." WHERE MaDonDatHang=$id";
					
					echo($sql);
					
					
					require_once "../../database/DataProvider.php";
					$result =  DataProvider::ExecuteQuery($sql);
					echo($result);
				}
				header ("Location: ../admin_manager_order.php");
			}
			?>
		</td>
	</tr>
</table>
</body>
</html>

